<template>
	<view class="container">
		<u-navbar :is-back="false" :title="title" title-color="white" :background="background"></u-navbar>
		<view class="hotList">
			<view class="item_wrap" v-for="(item,index) in hotActivityList" :key="index">
				<view class="card" @click="cardClick(item.id)">
					<view class="top">
						<text>{{item.title}}</text>
					</view>
					<view class="middle">
						<view class="left">
							<image :src="item.img" mode="aspectFill"></image>
						</view>
						<view class="right">
							<view class="content">
								<text>{{item.detail}}</text>
							</view>
							<view class="tags">
								<view v-for="(it,ind) in item.label" :key="ind">
									<view class="item">
										{{it}}
									</view>
								</view>
							</view>
						</view>
					</view>

					<view class="bottom">
						<view class="left">
							{{item.createTime}}
						</view>
						<view class="right">
							<view class="view">
								<u-icon name="eye" color="#99CCFF"></u-icon>
								<text>{{item.views}}</text>
							</view>
							<view class="zan">
								<u-icon name="thumb-up" color="#FF6666"></u-icon>
								<text>{{item.likes}}</text>
							</view>
							<view class="comments">
								<u-icon name="more-circle" color="#99CC66"></u-icon>
								<text>{{item.comments}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mybottom" v-if="isBottom">
				<text>这是我的底线</text>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '热门',
				background: {
					backgroundImage: 'linear-gradient(to right, #fa709a 0%, #fee140 100%)'
				},
				queryParams: {
					pageNum: 1,
					pageSize: 10
				},
				hotActivityList: [],
				isBottom: false
			}
		},
		onLoad() {
			this.init();

		},
		onReachBottom() {
			console.log("我被执行了")
			this.nextPage();
		},
		methods: {
			init() {

				this.$u.api.getHotActivityList(this.queryParams).then(res => {
					//console.log(JSON.stringify(res));
					this.hotActivityList = res.data.map(item => {
						item.label = item.label.split(",");
						return item;
					});
				})
			},
			nextPage() {
				if (!this.isBottom) {
					this.queryParams.pageNum++;
					//console.log(this.queryParams.pageNum);
					// this.activityList= [...this.activityList,...];
					let newActivityList;
					this.$u.api.getHotActivityList(this.queryParams).then(res => {
						//console.log(res.data.length);
						if (res.data.length != 0) {
							newActivityList = res.data.map(item => {
								item.label = item.label.split(",");
								return item;
							});
							this.hotActivityList = [...this.hotActivityList, ...newActivityList];
						} else {
							this.isBottom = true;
						}
						//console.log(JSON.stringify(res));
					})
					//console.log(this.activityList.length);
				} else {
					console.log("已经到底了");
				}
			},
			cardClick(id){
				uni.navigateTo({
					url:`../detail/detail?id=${id}`,
				});
			}

		}
	}
</script>

<style scoped lang="scss">
	.container {
		.hotList {
			.item_wrap {
				.card {
					width: 700rpx;
					height: 250rpx;
					display: flex;
					flex-direction: column;
					margin: 20rpx auto;
					// background-color: rgba($color: #000000, $alpha: 0.2);

					.top {
						text {
							font-size: 30rpx;
							font-weight: bold;
							display: -webkit-box;
							-webkit-line-clamp: 1;
							-webkit-box-orient: vertical;
							overflow: hidden;
							margin: 5rpx 10rpx;
						}
					}

					.middle {
						display: flex;
						height: 200rpx;

						.left {

							// background-color: rgba($color: #000000, $alpha: 0.3);
							image {
								width: 250rpx;
								height: 150rpx;
								margin: 0 20rpx 10rpx 10rpx;
								border-radius: 10rpx;

							}
						}

						.right {
							flex: 1;

							.content {
								text {
									display: -webkit-box;
									-webkit-line-clamp: 3;
									-webkit-box-orient: vertical;
									overflow: hidden;
								}
							}

							.tags {
								display: flex;
								width: 400rpx;
								white-space: nowrap;
								overflow: hidden;

								.item {
									margin-right: 20rpx;
									background-color: rgba($color: #000000, $alpha: 0.08);
									padding: 5rpx 10rpx;
									border-radius: 5rpx;
									font-size: 25rpx;

								}
							}
						}
					}

					.bottom {
						// flex: 1;
						display: flex;
						// background-color: rgba($color: #000000, $alpha: 0.5);
						height: 70rpx;
						align-items: center;
						justify-content: space-between;

						.left {
							font-size: 25rpx;
							margin-left: 10rpx;
						}

						.right {
							flex: 1;
							display: flex;
							justify-content: space-around;
							margin: 0 40rpx;

							.view {
								text {
									margin-left: 8rpx;
								}
							}

							.zan {
								text {
									margin-left: 8rpx;
								}
							}

							.comments {
								text {
									margin-left: 8rpx;
								}
							}
						}
					}
				}

				
			}
			.mybottom {
				display: flex;
				justify-content: center;
				align-items: center;
				margin-bottom: 50rpx;
			
				text {
					font-size: 30rpx;
					color: grey;
				}
			}
		}
	}
</style>
